home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
login.zip
/
GETFLD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-03
|
927b
|
54 lines
#include <stdio.h>
#ifdef MAIN
char *getfld();
main()
{
int x;
char b[] = "root:foo-bar:shell";
char c[] = "root::shell";
char *d;
printf("b=%s\n", b);
for (x = 0; x < 3; ++x)
printf("field:%d = [%s]\n", x, getfld(b, x, ':'));
printf("c=%s\n", c);
for (x = 0; x < 3; ++x)
printf("field:%d = [%s]\n", x, getfld(c, x, ':'));
}
#endif
char *
getfld(a, b, c)
char *a, c;
int b;
{
char *p, *e;
p = a;
while (*a != '\0') {
if (*a == c) {
if (b == 0) {
*a = '\0';
if ((e = (char *)malloc(strlen(p)+1)) == NULL)
return (NULL);
strcpy(e, p);
*a = c;
return(e);
}
*a++;
p = a;
--b;
continue;
}
*a++;
}
if (b == 0) {
if ((e = (char *)malloc(strlen(p)+1)) == NULL)
return (NULL);
strcpy(e, p);
return(e);
}
return(NULL);
}